package com.zhx.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.github.pagehelper.PageInfo;
import com.zhx.entity.TbRuralCMSOffice;
import com.zhx.service.RuralCMSOfficeService;

@Controller
@RequestMapping("/ruralCMSOffice")
public class RuralCMSOfficeController {

	@Autowired
	private RuralCMSOfficeService ruralCMSOfficeService;
	
	/**
	 * 获取农合机构信息列表，包含模糊查询，分页
	 * @param currentPage
	 * @param limit
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("/getList")
	public String getList(Integer currentPage, Integer limit,HttpServletRequest request, Model model){
		String officeName = request.getParameter("context");
		currentPage = currentPage != null ? currentPage : 1;
		limit = limit != null ? limit : 10;
		
		PageInfo<TbRuralCMSOffice> pageInfo = ruralCMSOfficeService.getRuralCMSOfficeList(currentPage, limit, officeName);
		
		model.addAttribute("pageInfo", pageInfo);
		model.addAttribute("context", officeName);
		return "/office/office_list";
	}
	
	@RequestMapping("/openAdd")
	public String openAdd(){
		return "/office/office_add";
	}
	
	public String openEdit(){
		return "";
	}
	
	@RequestMapping("/add")
	public String add(TbRuralCMSOffice tbRuralCMSOffice,HttpServletRequest request, Model model){
		ruralCMSOfficeService.add(tbRuralCMSOffice);
		return getList(1, 10, request, model);
	}
	
	public String edit(){
		return "";
	}
	
	public String delete(){
		return "";
	}
	
	
}
